package com.shut.vehicle.controller;

import com.shut.vehicle.controller.result.Result;
import com.shut.vehicle.interceptor.token.Back;
import com.shut.vehicle.interceptor.token.Client;
import com.shut.vehicle.interceptor.token.UserThread;
import com.shut.vehicle.pojo.Device;
import com.shut.vehicle.pojo.ServiceRecord;
import com.shut.vehicle.service.BookingRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 卢斌
 */
@CrossOrigin
@ResponseBody
@Controller
@RequestMapping(value = "/service_record")
public class BookingRecordController {

    @Autowired
    private BookingRecordService bookingRecordService;


    @Client
    @PostMapping(value = "/booking_snapshot")
    public Result bookingRecord(@RequestBody ServiceRecord record) {
        Integer userId = UserThread.userId();
        bookingRecordService.bookingSnapshot(userId, record.getDeviceId(), record.getCardId());
        return Result.ok();
    }


    @Client
    @GetMapping(value = "/snapshot_record")
    public Result bookingRecord(@RequestParam(value = "deviceId", required = false) Integer deviceId, @RequestParam("hasFinished") Boolean hasFinished, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        Integer userId = UserThread.userId();
        List<ServiceRecord> bookingRecord = bookingRecordService.listServiceRecord(userId, deviceId, hasFinished, pageNum, pageSize);
        return Result.okList(bookingRecord);
    }



    @Back
    @GetMapping(value = "/snapshot_record_back")
    public Result bookingRecordBack(@RequestParam(value = "deviceId", required = false) Integer deviceId, @RequestParam(value = "userId", required = false) Integer userId, @RequestParam("hasFinished") Boolean hasFinished, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        List<ServiceRecord> bookingRecord = bookingRecordService.listServiceRecord(userId, deviceId, hasFinished, pageNum, pageSize);
        return Result.okList(bookingRecord);
    }

}
